package com.nq.activaity.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.nq.activaity.dto.UserInviteRecordDto;
import com.nq.activaity.entity.StUserInviteRecord;
import com.nq.activaity.service.IStUserInviteRecordService;
import com.nq.common.ServerResponse;
import com.nq.dao.activaity.StUserInviteRecordMapper;
import com.nq.pojo.User;
import com.nq.service.IUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Description: 邀请赠送积分表
 * @Author: jeecg-boot
 * @Date:   2024-11-07
 * @Version: V1.0
 */
@Service
public class StUserInviteRecordServiceImpl extends ServiceImpl<StUserInviteRecordMapper, StUserInviteRecord> implements IStUserInviteRecordService {

    @Resource
    private IUserService userService;

    @Resource
    private StUserInviteRecordMapper userInviteRecordMapper;

    @Override
    public ServerResponse list(Integer pageNum, Integer pageSize, HttpServletRequest request) {
        User user = this.userService.getCurrentRefreshUser(request);
        if (user == null) {
            return ServerResponse.createByErrorMsg("The user does not exist");
        }
        PageHelper.startPage(pageNum, pageSize);
        List<UserInviteRecordDto> userInviteRecordList = userInviteRecordMapper.list(user.getId());
        PageInfo pageInfo = new PageInfo(userInviteRecordList);
        return ServerResponse.createBySuccess(pageInfo);
    }
}
